<?php
namespace Blind\Controller;
use Think\Controller;
class FeatureController extends Controller {

	//跳转到景区列表页面
    public function featureList()
    {
        $res = M('feature') ->order('recommend desc') -> select();
        $this -> assign('data', $res);
        // 查询出所有景点
        $this -> display();
    }

    //新建页面
    public function featureAdd()
    {
        $this -> display();
    }


    public function upload(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
        $upload->savePath  =     ''; // 设置附件上传（子）目录
        // 上传文件 
        $info   =   $upload->upload();

        if($info == false) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else
        {// 上传成功
            
           return $info;
        }
    }

             
        


    public function doAdd()
    {
    	//获取所有传过来的数据
        $data['name'] = I('post.name');
        $data['recommend'] = I('post.recommend');
    	$data['introduce'] = I('post.introduce');
        $img = I('post.image');

        $imgInfo = $this -> upload();
        $data['img'] = $imgInfo['image']['savepath'].$imgInfo['image']['savename'];

        $res = M('feature') -> add($data);
        if($res)
        {
            $this -> success('成功', 'featureList');
        }else
        {
            $this -> error('失败');
        }
    }

    public function delFea($id)
    {
        $res = M('feature') -> where("id=%d",$id) -> delete();
        if($res)
        {
            $this -> success('成功');
        }else
        {
            $this -> error('失败');
        }
    }


    //编辑广告
    public function updFea()
    {
        $data = I('post.');
        $id = I('post.id');
        $res = M('feature') -> where("id=%d",$id)-> save($data);
        if($res)
        {
            $this -> success('成功', 'featureList');
        }else
        {
            $this -> error('失败');
        }
    }

    //编辑时获取单个广告的信息
    //
    public function findFea($id)
    {

        $res = M('feature') -> where("id=%d",$id) -> select();
        if($res)
        {
            $this -> assign('data', $res);
            $this -> display();
        }else
        {
            $this -> error('编辑失败');
        }

    }

}